package test.nettys.sec;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @Author wangshaopeng
 * @Date 2021/6/17
 */
public class MyClientHandler extends SimpleChannelInboundHandler<String> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        System.out.println("收到响应"+ctx.channel().remoteAddress()+msg);
        ctx.writeAndFlush(System.currentTimeMillis()+"");
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("练级饿了");
        ctx.writeAndFlush(System.currentTimeMillis()+"");
    }
}
